<?php 
/**
 * 缓存统一接口
 * 
 * [WeEngine System] Copyright (c) 2013 WE7.CC
 */
defined('IN_IA') or exit('Access Denied');

require IA_ROOT . "/source/function/cache.{$_W['config']['setting']['cache']}.func.php";

/**
 * 读取缓存，并将缓存加载至 $_W 全局变量中
 * @param string $key 缓存键名，如果键名以:结束，则做为分组名称读取所有缓存
 *
 */
function cache_load($key) {
    if(substr($key, -1) == ':') {
        global $_W;
        $data = cache_search($key);
        foreach($data as $k => $v) {
            $tmp = &cache_global($k);
            $tmp = $v;
        }
        return cache_global($key);
    } else {
        $data = cache_read($key);
        $tmp = &cache_global($key);
        $tmp = $data;
        return $data;
    }
}

function &cache_global($key) {
    global $_W;
    $keys = explode(':', $key);
    $tmp = &$_W['cache'];
    foreach($keys as $v) {
        if(empty($v)) {
            continue;
        }
        $tmp = &$tmp[$v];
    }
    return $tmp;
}
